@include('layout.header')

 <link rel="stylesheet" type="text/css" href="{{ URL::asset('css/login.css') }}" />
<script>
        $(function(){
//            var vh=document.documentElement.clientHeight+"px";
//            vh=(vh+70);
//            $('.wrap').css({height:vh});
            //$('.end').hide();
//            setTimeout(function(){
//                $('.begin').hide();
//                $('.end').show();
//            },800000);
            var offon=false;
            window.onkeyup=function(){
                var pwd=$('.pwd').val();
                var user=$('.user').val();
                if(pwd != '' && user != '' && pwd != '请输入密码' && user != '请输入手机号或用户名'){
                     offon=true;
                }
            };


        (function(){
                if(offon){
                    $('.zhuce').css({background:"#00a8ee",'color':"#fff",'cursor':'pointer'});
                }
            },500);
        })
</script>

<div class="wrap">
    <div class="login">
        <div class="logo"><img src="{{ URL::asset('/images/logo.png') }}"> </div>
        <div class="login_text">
            <span class="active">账号登录</span>
            <span>内部账号登录</span>
        </div>
        <form method="post" name="loginform">
            {{ csrf_field() }}
            <input type="tel" class="user" name="tel" placeholder="请输入注册手机号" <?php if(isset($_COOKIE['logintel'])){ ?> value="<?php echo $_COOKIE['logintel'];?>" <?php }else{ ?> value="{{ old('tel') }}" <?php } ?>>
            <input type="password" name="password" class="pwd" placeholder="请输入您的密码" <?php if(isset($_COOKIE['loginpass'])){ ?> value="<?php echo $_COOKIE['loginpass'];?>" <?php }else{ ?>  value="{{ old('password') }}" <?php } ?>>
            <span class="jishu_img">
                <input type="checkbox" name="remeber" class="remeber" checked="ckecked">
            </span>
            
            <span class="rempwd">记住密码{{ Cookie::get('laravel_sessio') }}</span>
            <span class="wangji"><a href='{{url("/getpwd")}}' style="cursor: pointer;color:#999ea4;">忘记密码?</a></span>
            <i class="zhuce" id="zhuce" style="background:#00a8ee;color:#fff;cursor: pointer;">登录</i>
        </form>
        <form method="post" name="PINform" style="display: none;">
            {{ csrf_field() }}
            <input type="tel" class="user PINuser" id="PINtel" name="tel" placeholder="账户" <?php if(isset($_COOKIE['logintel'])){ ?> value="<?php echo $_COOKIE['logintel'];?>" <?php }else{ ?> value="{{ old('tel') }}" <?php } ?>>
            <input type="password" name="password" id="PINpassword" class="pwd PINpwd" placeholder="密码" <?php if(isset($_COOKIE['loginpass'])){ ?> value="<?php echo $_COOKIE['loginpass'];?>" <?php }else{ ?>  value="{{ old('password') }}" <?php } ?>>
            <span class="jishu_img">
                <input type="checkbox" name="PINremeber" class="remeber PINrember" checked="ckecked">
            </span>

            <span class="rempwd">记住密码{{ Cookie::get('laravel_sessio') }}</span>
            <span class="wangji"><a href='{{url("/getpwd")}}' style="cursor: pointer;color:#999ea4;">忘记密码?</a></span>
            <i class="zhuce" id="PINlogin" style="background:#00a8ee;color:#fff;cursor: pointer;">登录</i>
        </form>
    </div>
    <div class="modal">
        <!--<img src="{{ URL::asset('/images/gif.jpg') }}" class="end">-->
        <img src="{{ URL::asset('/images/gif-6s.gif') }}" class="begin">
    </div>
</div>
<script>
    $(".login_text span").click(function(){
        $(".login_text span").eq($(this).index()).addClass("active").siblings().removeClass('active');
        $("form").hide().eq($(this).index()).show();
        //另一种方法: $("div").eq($(".tab li").index(this)).addClass("on").siblings().removeClass('on');
    });
    $('.header_l ul li a').css({'border-bottom':'0px #fff','color':'#000'});
    $('.header_r a:eq(0)').css({'border-bottom':'3px solid #04b1f9','color':'#04b1f9'});
    var telurl    = "{{url('/checktel') }}";
    var gotologin = "{{url('/gotologin?type=1')}}";
    var gotourl = "{{ url('/') }}";
    var setpinurl = "{{url('/setpin')}}";
    $(document).keydown(function(event){ 
		if(event.keyCode==13){ 
			$(".zhuce").click(); 
		} 
	});
    // 手机账户登录
    $(function(){
        $('#zhuce').click(function() {
            //验证手机号
            var moblie = $("input[name=tel]").val();
            if(!(/^(13|14|15|17|18)\d{9}$/.test(moblie))){
                layer.tips('请输入正确的手机号!','.user', {
                    tips: [1, '#3595CC'],
                    time: 1000
                });
            }else if(!$("input[name=password]").val()){
                layer.tips('请输入您的登录密码!','.pwd', {
                    tips: [1, '#3595CC'],
                    time: 1000
                });
            }else{
                $('#zhuce').css('background','#424254');
                $('#zhuce').html('登录中。。。');
                $.ajax({
                    url:telurl,
                    type: 'post',
                    data: {tel:moblie},
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                    success: function(res){
                        if(parseInt(res) === 0){
                            $('#zhuce').css('background','#00a8ee');
                            $('#zhuce').html('登录');
                            layer.tips('该手机号未注册!','.user');
                        }else{
                            var mydata=$("form[name=loginform]").serialize();
                            $.ajax({
                                url:gotologin,
                                type: 'post',
                                data: mydata,
                                dataType:'json',
                                success: function(res){
                                    if(res.status == 1){
                                        //登录成功
                                        window.location.href = gotourl;
                                    }else{
                                        //登录失败
                                        $('#zhuce').css('background','#00a8ee');
                                        $('#zhuce').html('登录');
                                        layer.tips('您输入的密码不正确!','.pwd');
                                        //window.location.reload();
                                    }
                                }
                            });
                        }
                    }
                });
            }
        });
    })
    // PIN用户登录
    $(function(){
        $('#PINlogin').click(function() {
            //验证手机号
            var moblie = $("input[id=PINtel]").val();
            if(!(/^[a-zA-Z]{5}\d{4}$/.test(moblie))){
                layer.tips('请输入正确的账号!','form[name=PINform] .PINuser', {
                    tips: [1, '#3595CC'],
                    time: 1000
                });
                return false;
            }else if(!$("input[id=PINpassword]").val()){
                layer.tips('请输入您的登录密码!','form[name=PINform] .PINpwd', {
                    tips: [1, '#3595CC'],
                    time: 1000
                });
                return false;
            }else{
                $('#PINlogin').css('background','#424254');
                $('#PINlogin').html('登录中。。。');
                $.ajax({
                    url:telurl,
                    type: 'post',
                    data: {tel:moblie},
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                    success: function(res){
                        if(parseInt(res) === 0){
                            $('#PINlogin').css('background','#00a8ee');
                            $('#PINlogin').html('登录');
                            layer.tips('该账号不存在!','.PINuser');
                        }else{
                            var mydata=$("form[name=PINform]").serialize();
                            $.ajax({
                                url:gotologin,
                                type: 'post',
                                data: mydata,
                                dataType:'json',
                                success: function(res){
                                    if(res.status == 1){
                                        if(res.jihuo == 1){ //如果用户已激活
                                             window.location.href = gotourl;
                                        }else{
                                            //登录成功
                                            window.location.href = setpinurl;
                                        }
                                        
                                    }else{
                                        //登录失败
                                        $('#PINlogin').css('background','#00a8ee');
                                        $('#PINlogin').html('登录');
                                        layer.tips('您输入的密码不正确!','.PINpwd');
                                        //window.location.reload();
                                    }
                                }
                            });
                        }
                    }
                });
            }
        });
    })
</script>